package com.casic.worklog.service;

import com.casic.worklog.dao.EmployeeMapper;
import com.casic.worklog.model.Employee;
import com.casic.worklog.model.vo.Result;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service

/**
 * @author 黄志
 * @date 2019-09-13 14:08
 * @param null
 * @return
 * @throws
 *
*/
public class EmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;

    public Employee loginCheck (String username, String password) {
        Employee employee = employeeMapper.loginCheck(username, password);
        return employee;
    }

    public List<Employee> pageComment () {
        List<Employee> employeeList = employeeMapper.pageComment();
        return employeeList;
    }
    /**
     * 携带分页数据的员工信息
     */
    public Result findUserBy (int pageNum, int pageSize,Employee employee) {
        PageHelper.startPage(pageNum, pageSize);
        Page< Employee > employeePage = employeeMapper.findUserBy(employee);
        Long count = employeePage.getTotal();
        if (employeePage != null) {
            //员工数量
            return Result.ok().put(employeePage).put("count", count);
        } else {
            return Result.error();
        }
    }

    /**
     * 根据主键删除用户
     */
    public int deleteEmploy (Short id) {
        return employeeMapper.deleteEmploy(id);
    }
    /**
     * 批量删除用户
     */
    public int deleteArrays (int[] id) {
        return employeeMapper.deleteArrays(id);

    }
    /**
     * 根据主键查找用户
     */
    public Employee findUserById (Short id) {
        return employeeMapper.findUserById(id);
    }

    /**
     * 更新人员信息
     */
    public void updateUser (Employee employee){
         employeeMapper.updateUser(employee);
    };


    /**
     * 新增人员信息
     */
    public void insertUser (Employee employee){
        employeeMapper.insertUser(employee);
    };

    public Employee findByUsername(String userName) {
        return employeeMapper.findByUsername(userName);
    }


}
